/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Application;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

/**
 *
 * @author Stanley
 */
public class Options extends List implements CommandListener{
    private MainMidlet midlet;
    private Command back;
    private Command select;
    
    public Options(MainMidlet midlet) {
        super("Options", List.IMPLICIT);
        // command
        back = new Command("Back", Command.BACK, 1);
        select = new Command("Select", Command.SCREEN, 1);
        append("Search", null);
        append("Find path", null);
        append("Map type", null);
        append("Find coordinates", null);
        append("Exit", null);
        
        this.midlet = midlet;
        
        // add command
        setCommandListener(this);
        addCommand(back);
        addCommand(select);
        setSelectCommand(select);
    }
    public void commandAction(Command c, Displayable d) {
        if (c == back) {
            midlet.homeShow();
        } else if (c == select) {
            List list = (List) d;
            int selectedIdx = list.getSelectedIndex();
            switch (selectedIdx) {
                case 0:
                    midlet.searchShow();
                    break;
                case 1:
                    // find path
                    midlet.findPathShow();
                    break;
                case 2:
                    // map type
                    midlet.mapTypeShow();
                    break;
                case 3: // find the coordinates
                    midlet.findCoordinatesShow();
                    break;
                default:
                    midlet.exitMIDlet();
                    break;
            }
        }
    }
}
